package fhp.hlhj.giantfold.activity.malls
import android.os.Build
import android.support.annotation.RequiresApi
import android.support.v7.widget.GridLayoutManager
import android.view.LayoutInflater
import android.view.View
import fhp.hlhj.giantfold.BaseActivity2
import fhp.hlhj.giantfold.R
import fhp.hlhj.giantfold.interfaces.ITaoBao
import fhp.hlhj.giantfold.adapter.TabBaoHeaderGridViewAdp
import fhp.hlhj.giantfold.adapter.TaoBaoRcyAdp
import fhp.hlhj.giantfold.presenter.TaoBaoPresenter
import kotlinx.android.synthetic.main.activity_tab_bao_aty.*
import kotlinx.android.synthetic.main.tabbao_header.view.*

class TabBaoAty : BaseActivity2<ITaoBao, TaoBaoPresenter>(), ITaoBao {
    private lateinit var adapter: TaoBaoRcyAdp
    private lateinit var headAdapter:TabBaoHeaderGridViewAdp
    private lateinit var  header:View
    override fun showLoading() {

    }
    override fun showData(datas: List<String>) {
        val gridManager=GridLayoutManager(this,2)
        adapter = TaoBaoRcyAdp(R.layout.tabbao_item,datas)
        recyclerview.layoutManager=gridManager
        recyclerview.adapter=adapter
        adapter.addHeaderView(header)
    }
    override fun showHeadData(datas: List<String>) {
        headAdapter= TabBaoHeaderGridViewAdp(this,datas)
        header.gridView.adapter=headAdapter
    }
    override fun createPresenter(): TaoBaoPresenter {
        basePresenter=TaoBaoPresenter(this)
        return basePresenter
    }
    override fun getContentId(): Int = R.layout.activity_tab_bao_aty
    override fun initView() {
        header =LayoutInflater.from(this).inflate(R.layout.tabbao_header,null)
        basePresenter.fetchData()
    }
    @RequiresApi(Build.VERSION_CODES.M)
    override fun initListener() {
        btGoTop.setOnClickListener {
            recyclerview.scrollToPosition(0)
        }
        header.btExit.setOnClickListener {
            finish()
        }
    }
}
